//查询专题
export const queryTopic = function(queryString, cb) {
  let TopicData = [];
  if (queryString != "") {
    this.axios.post("/topic/getTopicByIdOrName", { queryString })
      .then(res => {
        if (res.length > 0) {
          res.forEach(item => {
            TopicData.push({id: item.id,value: item.name});
          });
        } else {
          TopicData.push({id: -1, value: "无搜索结果" });
        }
      });
  } else {
    TopicData.push({id: -1, value: "无搜索结果" });
  }
  cb(TopicData);
}

//查询标签
export const queryTags = function(queryString, cb) {
  let TagsData = [];
  if (queryString != "") {
    this.axios.post("/tag/getTagByIdOrName", { queryString }).then(res => {
      if (res.length > 0) {
        res.forEach(item => {
          TagsData.push({
            id: item.id,
            value: item.name
          });
        });
      } else {
        TagsData.push({id: -1, value: "无搜索结果" });
      }
    });
  } else {
    TagsData.push({id: -1, value: "无搜索结果" });
  }
  cb(TagsData);
}

//查询分类
export const queryCategory = function(queryString, cb) {
  let categoryData = [];
  if (queryString != "") {
    this.axios.post("/category/findByIdorName", { queryString }).then(res => {
      if (res.length > 0) {
        res.forEach(item => {
          categoryData.push({ id: item.id, value: item.name});
        });
      } else {
        categoryData.push({id: -1, value: "无搜索结果" });
      }
    });
  } else {
    categoryData.push({id: -1, value: "无搜索结果" });
  }
  cb(categoryData);
}
